
import java.awt.*;
import java.util.*;

public class Tile{
	private int slot;
	private int x;
	private int y;
	private int type;
	private int dieNum;
	private int size;
	private TileDisplay tileDisplay;
	
	public Tile(int slot, int type, int size) {
		this.slot = slot;
		this.type = type;
		this.tileDisplay = new TileDisplay(this);
		x = findX(slot);
		y = findY(slot);
		this.size = size;
		
	}
	
	//generates an appropriate random dieNum based on previous dieNums
	public boolean dieNumGenerator(ArrayList<Tile> tiles){
		int dieNum = (int)(Math.random() * 11 + 2);
		int[] counts = new int[13];
		for(Tile tile: tiles){
			counts[tile.getDieNum()]++;
		}
		if(type == 6){
			this.dieNum = 0;
			return true;
		} else if(dieNum == 7){
			return false;
		} else if(counts[dieNum] == 0){
			this.dieNum = dieNum;
			return true;
		} else if(counts[dieNum] == 1 && dieNum != 2 && dieNum != 12) {
			this.dieNum = dieNum;
			return true;
		} else {
			return false;
		}
	}
	
	public int getDieNum(){
		return dieNum;
	}
	
	public int getType(){
		return type;
	}
	
	public String toString(){
		return slot + " ";
	}
	
	//finds the row of X values the tile starts at for drawing
	private int findX(int slot){
		return this.tileDisplay.getX();
	}
	
	//finds the row of Y values the tile starts at for drawing
	private int findY(int slot){
		return this.tileDisplay.getY();
	
	}
	
	public int getSlot() {
		return slot;
	}

	public void setSlot(int slot) {
		this.slot = slot;
	}

	public int getX() {
		return x;
	}

	public void setX(int x) {
		this.x = x;
	}

	public int getY() {
		return y;
	}

	public void setY(int y) {
		this.y = y;
	}

	public void setType(int type) {
		this.type = type;
	}

	public void setDieNum(int dieNum) {
		this.dieNum = dieNum;
	}
	
	
	

	public TileDisplay getTileDisplay() {
		return tileDisplay;
	}

	public void setTileDisplay(TileDisplay tileDisplay) {
		this.tileDisplay = tileDisplay;
	}

	public void drawSelf(int size2, Graphics g) {
		// TODO Auto-generated method stub
		tileDisplay.drawSelf(size2, g);
	}

}
